clear all
set more off
	
global dir = "C:\Users\mrueda\Documents\Emory\Papers\Networks_persistance\do_files\do_files_APSA21\post_JOP\Replication_BJPS\"	


cd "$dir"

use "Data\donor_level_persist_rep.dta",clear
*New donor-level family (f) and (nf) variable generation
keep if rank==1|rank==2
replace b5=. if b2!=0

gen nfdonate_15any = donate_15any if family==0
gen fdonate_15any = donate_15any if family==1
gen nfb5 = b5 if family==0
gen fb5 = b5 if family==1


gen treat=0
replace treat=1 if margin_victory>0&margin_victory~=.
replace treat=. if margin_victory==.

gen treat_margin_victory=treat*margin_victory

	texdoc close 
	cap erase "$dir/Tables/TableG7.tex"
	texdoc init "$dir/Tables/TableG7.tex", force
	
	tex \begin{table}[tbph]
	tex \caption{Effect of donating to an election winner on future donations (candidate's family members vs. Non members global parametric linear RD)}\label{tab:donation_fam_nofam_l_ols}
	tex \centering
	tex \begin{tabular}{l c c } \hline
	tex Outcome : & Any race & Mayor  \\ 
	tex & (1) & (2)  \\ \hline
	tex \multicolumn{2}{l}{Panel A: Candidates' family members}\\
	tex & &  \\
	
	*Model 1
	foreach var in donate_15any b5{
		
		quietly: regress f`var' treat sanc_before ilegal p_prop elec_exp pol_exp_d center rank_don_alt_all lcont_donor_all contraloria above_lim, vce(cluster muni_code)
		quietly sum f`var' if e(sample)
			local fmean_`var' : di %5.3f r(mean)
			local fsd_`var' : di %5.3f r(sd) 		
		
		regress f`var' treat sanc_before ilegal p_prop elec_exp pol_exp_d center rank_don_alt_all lcont_donor_all contraloria above_lim, vce(cluster muni_code)

		local fN_`var' : di %5.0f e(N)
		local fR2_`var' : di %5.3f e(r2)

		matrix b = e(b)
		matrix v = e(V)
		matrix res=r(table)
		
		local fb1_`var' : di %5.3f b[1,1]
		local fse1_`var' : di %5.3f sqrt(v[1,1])
		local fp_v_`var' :di %5.3f res[4,1]
		local fuci_`var': di %5.3f res[6,1]
		local flci_`var': di %5.3f res[5,1]


		areg f`var' treat sanc_before ilegal p_prop elec_exp pol_exp_d center rank_don_alt_all lcont_donor_all contraloria above_lim if e(sample),absorb(muni_code) vce(cluster muni_code)


		matrix bf = e(b)
		matrix vf = e(V)
		matrix resf=r(table)
		
		local fb1f_`var' : di %5.3f bf[1,1]
		local fse1f_`var' : di %5.3f sqrt(vf[1,1])
		local fp_vf_`var' :di %5.3f resf[4,1]
		local fucif_`var': di %5.3f resf[6,1]
		local flcif_`var': di %5.3f resf[5,1]
		
		
		*No Family
		*Regressions
		*Summary statistics for the mean
			quietly: regress nf`var' treat sanc_before ilegal p_prop elec_exp pol_exp_d center rank_don_alt_all lcont_donor_all contraloria above_lim, vce(cluster muni_code)
			quietly sum nf`var' if e(sample)
			local nfmean_`var' : di %5.3f r(mean)
			local nfsd_`var' : di %5.3f r(sd) 		
		
		regress nf`var' treat sanc_before ilegal p_prop elec_exp pol_exp_d center rank_don_alt_all lcont_donor_all contraloria above_lim, vce(cluster muni_code)

		local nfN_`var' : di %5.0f e(N)
		local nfR2_`var' : di %5.3f e(r2)

		matrix b = e(b)
		matrix v = e(V)
		matrix res=r(table)
		
		local nfb1_`var' : di %5.3f b[1,1]
		local nfse1_`var' : di %5.3f sqrt(v[1,1])
		local nfp_v_`var' :di %5.3f res[4,1]
		local nfuci_`var': di %5.3f res[6,1]
		local nflci_`var': di %5.3f res[5,1]
	
	
	areg nf`var' treat sanc_before ilegal p_prop elec_exp pol_exp_d center rank_don_alt_all lcont_donor_all contraloria above_lim if e(sample), absorb(muni_code) vce(cluster muni_code)
	
	matrix bf = e(b)
		matrix vf = e(V)
		matrix resf=r(table)
		
		local nfb1f_`var' : di %5.3f bf[1,1]
		local nfse1f_`var' : di %5.3f sqrt(vf[1,1])
		local nfp_vf_`var' :di %5.3f resf[4,1]
		local nfucif_`var': di %5.3f resf[6,1]
		local nflcif_`var': di %5.3f resf[5,1]
	
	
	}
	
	*Continue table
	tex Electoral victory & `fb1_donate_15any' & `fb1_b5'  \\
	tex \ \ \ \ Robust p-value & `fp_v_donate_15any' & `fp_v_b5' \\
	tex \ \ \ \ CI 95\%  & [`flci_donate_15any',`fuci_donate_15any'] & [`flci_b5',`fuci_b5']  \\
	tex & &  \\

	tex Electoral victory (FE) & `fb1f_donate_15any' & `fb1f_b5'  \\
	tex \ \ \ \ Robust p-value & `fp_vf_donate_15any' & `fp_vf_b5' \\
	tex \ \ \ \ CI 95\%  & [`flcif_donate_15any',`fucif_donate_15any'] & [`flcif_b5',`fucif_b5']  \\
	tex & & \\
	
	tex Observations & `fN_donate_15any' & `fN_b5' \\
	tex Mean & `fmean_donate_15any' & `fmean_b5' \\
	
	tex & & \\ \hline
	tex {Panel B: Non-family members}&  \\  
	tex & &  \\

		tex Electoral victory & `nfb1_donate_15any' & `nfb1_b5'  \\
	tex \ \ \ \ Robust p-value & `nfp_v_donate_15any' & `nfp_v_b5' \\
	tex \ \ \ \ CI 95\%  & [`nflci_donate_15any',`nfuci_donate_15any'] & [`nflci_b5',`nfuci_b5']  \\
	tex & &  \\
	
	tex Electoral victory (FE) & `nfb1f_donate_15any' & `nfb1f_b5'  \\
	tex \ \ \ \ Robust p-value & `nfp_vf_donate_15any' & `nfp_vf_b5' \\
	tex \ \ \ \ CI 95\%  & [`nflcif_donate_15any',`nfucif_donate_15any'] & [`nflcif_b5',`nfucif_b5']  \\
	tex & & \\
	
	tex Observations & `nfN_donate_15any' & `nfN_b5' \\
	tex Mean & `nfmean_donate_15any' & `nfmean_b5' \\ \hline
	tex \end{tabular}
	tex \parbox{160mm}{ \footnotesize{
	tex \footnotesize{Ordinary least squares (OLS) estimates of the effect of donating to the winner on donating in the next election. All models include as controls: candidate's illegal registration of ID, being sanctioned by the Office of the Inspector General, elected posts, ran as candidate in past elections, party is not left-wing or right-wing, and non-family donations as a fraction of campaign revenue, logged value of donation, donated above legal limit, sanctioned, rank of donation among all donors. FE denote municipality fixed effects. Confidence intervals and p-values with clusters at the municipality level.
	tex }
	tex }}
	tex \end{table}
	cap texdoc close 
	
	
